package normalEndPoint

import (
	"fmt"
	"github.com/gin-gonic/gin"
	"taofoo.top/learn/common"
	"taofoo.top/learn/dao"
	"taofoo.top/learn/ginHelper"
)

func Index(c *gin.Context) {
	c.JSON(200, gin.H{
		"message": "success",
	})
}

func Html(c *gin.Context) {
	info := common.PageInfo{}
	c.ShouldBindQuery(&info)
	list := dao.List(info)
	fmt.Println(list)
	c.HTML(200, "index.tmpl", gin.H{
		"title": "html_GO",
		"nums":list,
	})
}

func List(c *gin.Context) {
	info := common.PageInfo{}
	c.ShouldBindQuery(&info)
	c.JSON(200, gin.H{
		"resp": dao.List(info),
	})
}

func init() {
	dao.Connect()
	group := ginHelper.NewGroupAndRegister("v1","测试接口")
	group.RegisterHandler(ginHelper.BaseHandler{BName: "/list", BGinHandler: List,
		BOptionMask: ginHelper.GetPostOptionMask})
	group.RegisterHandler(ginHelper.BaseHandler{BName: "/html", BGinHandler: Html})
	group.RegisterHandler(ginHelper.BaseHandler{BName: "/",BGinHandler: Index})
}
